home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 August: Tool Chest / Dev.CD Aug 00 TC Disk 2.toast / pc / sample code / quicktime / wired movies and sprites / qtwiredsprites / application files / comapplication.c next >
Encoding:
Text File  |  2000-06-23  |  9.1 KB  |  384 lines

  1. //////////
  2. //
  3. //    File:        ComApplication.c
  4. //
  5. //    Contains:    Application-specific code for basic QuickTime movie display and control.
  6. //                This file is used for BOTH MacOS and Windows.
  7. //
  8. //    Written by:    Tim Monroe
  9. //                Based (heavily!) on the MovieShell code written by Apple DTS.
  10. //
  11. //    Copyright:    © 1994-1997 by Apple Computer, Inc., all rights reserved.
  12. //
  13. //    Change History (most recent first):
  14. //
  15. //       <12>         12/16/98    rtm        removed all QTVR API calls, so we can remove QTVR.lib from project
  16. //       <11>         03/25/98    rtm        modified for wired sprites sample
  17. //       <10>         10/23/97    rtm        moved InitializeQTVR to InitApplication, TerminateQTVR to StopApplication
  18. //       <9>         10/13/97    rtm        reworked HandleApplicationMenu to use menu identifiers
  19. //       <8>         09/11/97    rtm        merged MacApplication.c and WinApplication.c into ComApplication.c
  20. //       <7>         08/21/97    rtm        first file for Windows; based on MacApplication.c for Mac sample code
  21. //       <6>         06/04/97    rtm        removed call to QTVRUtils_IsQTVRMovie in InitApplicationWindowObject
  22. //       <5>         02/06/97    rtm        fixed window resizing code
  23. //       <4>         12/05/96    rtm        added hooks into MacFramework.c: StopApplication, InitApplicationWindowObject
  24. //       <3>         12/02/96    rtm        added cursor updating to DoIdle
  25. //       <2>         11/27/96    rtm        conversion to personal coding style; added preliminary QTVR support
  26. //       <1>         12/21/94    khs        first file
  27. //       
  28. //////////
  29.  
  30. // header files
  31.  
  32. #include "ComApplication.h"
  33. #include "QTWiredSprites.h"
  34.  
  35. // global variables for Macintosh code
  36. #if TARGET_OS_MAC
  37. #endif
  38.  
  39. long                        gMaxMilliSecToUse = 0L;    
  40.     
  41.  
  42. //////////
  43. //
  44. // InitApplication
  45. // Do any application-specific initialization.
  46. //
  47. // The theStartPhase parameter determines which "phase" of application start-up is executed,
  48. // *before* the MDI frame window is created or *after*. This distinction is relevant only on
  49. // Windows, so on MacOS, you should always use kInitAppPhase_BothPhases.
  50. //
  51. //////////
  52.  
  53. void InitApplication (UInt32 theStartPhase)
  54. {
  55.     // ***do any start-up activities that should occur before the MDI frame window is created
  56.     if (theStartPhase & kInitAppPhase_BeforeCreateFrameWindow) {
  57.     
  58.         // check to make sure that QuickTime wired sprites are available;
  59.         // we depend on these features  
  60.         if (!QTUtils_HasWiredSprites())
  61.             QuitFramework();
  62.         
  63.     }    // end of kInitAppPhase_BeforeCreateFrameWindow
  64. }
  65.  
  66.  
  67. //////////
  68. //
  69. // StopApplication
  70. // Do any application-specific shut-down.
  71. //
  72. // The theStopPhase parameter determines which "phase" of application shut-down is executed,
  73. // *before* any open movie windows are destroyed or *after*.
  74. //
  75. //////////
  76.  
  77. void StopApplication (UInt32 theStopPhase)
  78. {
  79.     // ***do any shut-down activities that should occur after the movie windows are destroyed
  80.     if (theStopPhase & kStopAppPhase_AfterDestroyWindows) {
  81.     
  82.     }    // end of kStopAppPhase_AfterDestroyWindows
  83. }
  84.  
  85.  
  86. //////////
  87. //
  88. // DoIdle
  89. // Do any processing that can/should occur at idle time.
  90. //
  91. //////////
  92.  
  93. void DoIdle (WindowReference theWindow)
  94. {
  95.     WindowObject         myWindowObject = NULL;
  96.     GrafPtr             mySavedPort;
  97.     
  98.     GetPort(&mySavedPort);
  99.     MacSetPort(GetPortFromWindowReference(theWindow));
  100.     
  101.     myWindowObject = GetWindowObjectFromWindow(theWindow);
  102.     if (myWindowObject != NULL) {
  103.         MovieController        myMC = NULL;
  104.     
  105.         myMC = (**myWindowObject).fController;
  106.         if (myMC != NULL) {
  107.  
  108. #if TARGET_OS_MAC
  109.             // restore the cursor to the arrow
  110.             // if it's outside the front movie window or outside the window's visible region
  111.             if (theWindow == GetFrontMovieWindow()) {
  112.                 Rect    myRect;
  113.                 Point    myPoint;
  114.                 
  115.                 GetMouse(&myPoint);
  116.                 MCGetControllerBoundsRect(myMC, &myRect);
  117.                 if (!MacPtInRect(myPoint, &myRect) || !PtInRgn(myPoint, GetPortFromWindowReference(theWindow)->visRgn))
  118.                     MacSetCursor(&qd.arrow);
  119.             }
  120. #endif    // TARGET_OS_MAC
  121.         }
  122.     }
  123.     
  124.     // @@@INSERT APPLICATION-SPECIFIC IDLE-TIME FUNCTIONALITY HERE
  125.     
  126.     MacSetPort(mySavedPort);
  127. }
  128.  
  129.  
  130. //////////
  131. //
  132. // DoUpdateWindow
  133. // Update the specified window.
  134. //
  135. //////////
  136.  
  137. void DoUpdateWindow (WindowReference theWindow, Rect *theRefreshArea)
  138. {
  139.     GrafPtr             mySavedPort;
  140.     
  141.     GetPort(&mySavedPort);
  142.     MacSetPort(GetPortFromWindowReference(theWindow));
  143.     
  144.     BeginUpdate(GetPortFromWindowReference(theWindow));
  145.     
  146.     // draw the movie controller and its movie
  147.     MCDoAction(GetMCFromWindow(theWindow), mcActionDraw, theWindow);
  148.     
  149.     EndUpdate(GetPortFromWindowReference(theWindow));
  150.     MacSetPort(mySavedPort);
  151. }
  152.  
  153.  
  154. //////////
  155. //
  156. // HandleContentClick
  157. // Handle mouse button clicks in the specified window.
  158. //
  159. //////////
  160.  
  161. void HandleContentClick (WindowReference theWindow, EventRecord *theEvent)
  162. {
  163. #pragma unused(theEvent)
  164.  
  165.     GrafPtr             mySavedPort;
  166.     
  167.     GetPort(&mySavedPort);
  168.     MacSetPort(GetPortFromWindowReference(theWindow));
  169.     
  170.     // @@@INSERT APPLICATION-SPECIFIC CONTENT CLICKING FUNCTIONALITY HERE
  171.  
  172.     MacSetPort(mySavedPort);
  173. }
  174.  
  175.  
  176. //////////
  177. //
  178. // HandleApplicationKeyPress
  179. // Handle application-specific key presses.
  180. // Returns true if the key press was handled, false otherwise.
  181. //
  182. //////////
  183.  
  184. Boolean HandleApplicationKeyPress (char theCharCode)
  185. {
  186.     Boolean        isHandled = true;
  187.     
  188.     switch (theCharCode) {
  189.     
  190.         // @@@HANDLE APPLICATION-SPECIFIC KEY PRESSES HERE
  191.  
  192.         default:
  193.             isHandled = false;
  194.             break;
  195.     }
  196.  
  197.     return(isHandled);
  198. }
  199.  
  200.  
  201. #if TARGET_OS_MAC
  202. //////////
  203. //
  204. // CreateMovieWindow
  205. // Create a window to display a movie in.
  206. //
  207. //////////
  208.  
  209. WindowRef CreateMovieWindow (Rect *theRect, Str255 theTitle)
  210. {
  211.     WindowRef            myWindow;
  212.         
  213.     myWindow = NewCWindow(NULL, theRect, theTitle, false, noGrowDocProc, (WindowPtr)-1L, true, 0);
  214.     return(myWindow);
  215. }
  216. #endif
  217.  
  218.  
  219. //////////
  220. //
  221. // HandleApplicationMenu
  222. // Handle selections in the application's menus.
  223. //
  224. // The theMenuItem parameter is a UInt16 version of the Windows "menu item identifier". 
  225. // When called from Windows, theMenuItem is simply the menu item identifier passed to the window proc.
  226. // When called from MacOS, theMenuItem is constructed like this:
  227. //     *high-order 8 bits == the Macintosh menu ID (1 thru 256)
  228. //     *low-order 8 bits == the Macintosh menu item (sequential from 1 to ordinal of last menu item in menu)
  229. // In this way, we can simplify the menu-handling code. There are, however, some limitations,
  230. // mainly that the menu item identifiers on Windows must be derived from the Mac values. 
  231. //
  232. //////////
  233.  
  234. void HandleApplicationMenu (UInt16 theMenuItem)
  235. {
  236.     switch (theMenuItem) {
  237.         case IDM_MAKE_SPRITE_MOVIE:
  238.             QTWired_CreateWiredSpritesMovie();
  239.             break;
  240.         default:
  241.             break;
  242.     } // switch (theMenuItem)
  243. }
  244.  
  245.  
  246. //////////
  247. //
  248. // AdjustApplicationMenus
  249. // Adjust state of items in the application's menus.
  250. //
  251. // Currently, the Mac application has only one app-specific menu ("Test"); you could change that.
  252. //
  253. //////////
  254.  
  255. void AdjustApplicationMenus (WindowReference theWindow, MenuReference theMenu)
  256. {
  257. #pragma unused(theWindow)
  258.     MenuReference            myMenu;
  259.     
  260. #if TARGET_OS_WIN32
  261.     myMenu = theMenu;
  262. #elif TARGET_OS_MAC
  263.     myMenu = GetMenuHandle(kTestMenu);
  264. #endif
  265.     
  266.     // we don't allow creating new files here...
  267. #if TARGET_OS_MAC
  268.     SetMenuItemState(GetMenuHandle(mFile), iNew, kDisableMenuItem);
  269. #endif
  270.     
  271. }
  272.  
  273.  
  274. //////////
  275. //
  276. // DoApplicationEventLoopAction
  277. // Perform any application-specific event loop actions.
  278. //
  279. // Return true to indicate that we've completely handled the event here, false otherwise.
  280. //
  281. //////////
  282.  
  283. Boolean DoApplicationEventLoopAction (EventRecord *theEvent)
  284. {
  285.     Boolean        isHandled = false;
  286.     
  287.     return(isHandled);
  288. }
  289.  
  290.  
  291. //////////
  292. //
  293. // AddControllerFunctionality
  294. // Configure the movie controller.
  295. //
  296. //////////
  297.  
  298. void AddControllerFunctionality (MovieController theMC)
  299. {
  300.     long            myControllerFlags;
  301.     
  302.     // CLUT table use    
  303.     MCDoAction(theMC, mcActionGetFlags, &myControllerFlags);
  304.     MCDoAction(theMC, mcActionSetFlags, (void *)(myControllerFlags | mcFlagsUseWindowPalette));
  305.  
  306.     // enable keyboard event handling    
  307.     MCDoAction(theMC, mcActionSetKeysEnabled, (void *)true);
  308.     
  309.     // disable drag support
  310.     MCDoAction(theMC, mcActionSetDragEnabled, (void *)false);
  311. }
  312.  
  313.  
  314. //////////
  315. //
  316. // InitApplicationWindowObject
  317. // Do any application-specific initialization of the window object.
  318. //
  319. //////////
  320.  
  321. void InitApplicationWindowObject (WindowObject theWindowObject)
  322. {
  323. #pragma unused(theWindowObject)
  324. }
  325.  
  326.  
  327. //////////
  328. //
  329. // RemoveApplicationWindowObject
  330. // Do any application-specific clean-up of the window object.
  331. //
  332. //////////
  333.  
  334. void RemoveApplicationWindowObject (WindowObject theWindowObject)
  335. {
  336. #pragma unused(theWindowObject)
  337.     // DoDestroyMovieWindow in MacFramework.c or MovieWndProc in WinFramework.c
  338.     // releases the window object itself
  339. }
  340.  
  341.  
  342. //////////
  343. //
  344. // ApplicationMCActionFilterProc 
  345. // Intercept some mc actions for the movie controller.
  346. //
  347. // NOTE: The theRefCon parameter is a handle to a window object record.
  348. //
  349. //////////
  350.  
  351. PASCAL_RTN Boolean ApplicationMCActionFilterProc (MovieController theMC, short theAction, void *theParams, long theRefCon)
  352. {
  353. #pragma unused(theMC, theParams)
  354.  
  355.     Boolean                isHandled = false;
  356.     WindowObject        myWindowObject = NULL;
  357.     
  358.     myWindowObject = (WindowObject)theRefCon;
  359.     if (myWindowObject == NULL)
  360.         return(isHandled);
  361.         
  362.     switch (theAction) {
  363.     
  364.         // handle window resizing
  365.         case mcActionControllerSizeChanged:
  366.             SizeWindowToMovie(myWindowObject);
  367.             break;
  368.  
  369.         // handle idle events
  370.         case mcActionIdle:
  371.             DoIdle((**myWindowObject).fWindow);
  372.             break;
  373.             
  374.         default:
  375.             break;
  376.             
  377.     }    // switch (theAction)
  378.     
  379.     return(isHandled);    
  380. }
  381.  
  382.  
  383.  
  384.